// 历史地图
<template>
  <div
    class="page-container page-container-havePagination"
    :class="{ 'page-container-haveFooter': $store.state.settings.showFooter }"
  >
    <!-- 工具栏 -->
    <div class="head-search-container">
      <!-- 搜索 -->
      <el-form
        :inline="true"
        label-position="right"
        label-width="74px"
        size="small"
        :model="searchQuery"
        class="demo-form-inline"
      >
        <el-form-item label="地图名称">
          <el-input
            class="search-btn"
            size="small"
            :clearable="true"
            v-model="searchQuery.name"
            placeholder="输入名称搜索"
            @change="search()"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            size="small"
            type="success"
            class="greenColor"
            @click="search"
            >查询</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            size="small"
            type="primary"
            class="greenColor"
            @click="addOrEdit(null,'add')"
            >添加地图</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格渲染 -->
    <el-table
      header-row-class-name="table-header-style"
      :row-class-name="tableRowStyle"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      v-loading="loading"
    >
			<el-table-column
				prop="sort"
				label="序号"
				sortable
			></el-table-column>
      <el-table-column
        prop="name"
        label="名称"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column label="漫游地址" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.url">{{
            scope.row.url ? scope.row.url : "暂无"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="相关文件" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.imageUrl">
            <template v-for="(item, index) in scope.row.imageUrl">
              <div :key="index">
                <el-image
                  style="width: 100px; height: 100px"
                  :src="item"
                  fit="contain"
                  :preview-src-list="scope.row.imageUrl"
                  v-if="item"
                ></el-image>
                <span v-else>暂无</span>
              </div>
            </template>
          </div>
          <div v-else>暂无</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="160px">
        <template slot-scope="scope">
          <el-button type="primary" @click="addOrEdit(scope.row, 'edit')"
            >编辑</el-button
          >
          <el-button @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <TablePagination
      :total="total"
      :currentPage="currentPage"
      :pageSize="pageSize"
      @changeSize="changeSize"
      @changePage="changePage"
      :class="[
        'table-pagination',
        { 'table-pagination-haveFooter': $store.state.settings.showFooter },
      ]"
    />
    <!-- 添加地图 -->
    <addMapPopup ref="addMapPopup" :type="type" :item="editRow" @update="init" />
  </div>
</template>
<script>
import { MessageBox } from "element-ui";
import initData from "@/mixins/req";
import addMapPopup from "./components/add.vue";
import { delMap } from "@/api/otherMap/index.js";
export default {
  name: "otherMap",
  mixins: [initData],
  components: {
    addMapPopup,
  },
  data() {
    return {
      searchQuery: {
        name: "", //名称
      },
      editRow: null,
      type: "add",
    };
  },
  created() {
    this.init();
  },
  methods: {
    search() {
      this.currentPage = 1;
      this.init();
    },
    reloadSearch() {
      this.search();
    },
    beforeInit() {
      this.url = "/oldCityOther/list";
      this.cType = 2;
      this.searchParams = {
        current: this.currentPage,
        limit: this.pageSize,
        ...this.searchQuery,
      };
      return true;
    },
    async del(row) {
      MessageBox.confirm("您确定要删除该地图吗？", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        const req = delMap({ ids: row.id });
        const res = await req;
        this.init();
      });
    },
    addOrEdit(row,type) {
      this.type = type;
      this.editRow = row;
      this.$refs.addMapPopup.show = true;
    },
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "~@/assets/styles/page.scss";
@import "~@/assets/styles/table.scss";
</style>

